package com.huxin.servelt;

import com.huxin.pojo.UserInfo;
import com.huxin.service.Userservice;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/updatereader")
public class UpdatereaderServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //获取请求方法
        request.setCharacterEncoding("utf-8");
        //处理响应乱码
        response.setContentType("text/json;charset=utf-8");
        String aid=request.getParameter("aid");
        String username=request.getParameter("username");
        String name=request.getParameter("name");
        String password=request.getParameter("password");
        String email=request.getParameter("email");
        String phone=request.getParameter("phone");
        String lend_num=request.getParameter("lend_num");
        String max_num=request.getParameter("max_num");
        //封装对象
        UserInfo reader = new UserInfo();
        reader.setAid(Integer.parseInt(aid));
        reader.setPassword(password);
        reader.setUsername(username);
        reader.setName(name);
        reader.setEmail(email);
        reader.setPhone(phone);
        reader.setLend_num(Integer.parseInt(lend_num));
        reader.setMax_num(Integer.parseInt(max_num));
        Userservice service = new Userservice();
        int i = service.updateUser(reader);
        if(i>0){
            response.sendRedirect("http://localhost:8080/web/html/admin/reader_list2.html");
        }
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doPost(request, response);
    }
}
